package com.loopj.ohos.http;

import cz.msebera.android.httpclient.Header;
import cz.msebera.android.httpclient.client.methods.HttpUriRequest;
import cz.msebera.android.httpclient.impl.client.DefaultHttpClient;
import cz.msebera.android.httpclient.protocol.HttpContext;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ExampleOhosTest {
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.loopj.ohos.http.sample", actualBundleName);
    }

    @Test
    public void testGet() {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient() {
            @Override
            protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
                return super.newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
            }
        };

        asyncHttpClient.get(AbilityDelegatorRegistry.getAbilityDelegator().getAppContext(), "url", null, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                assertEquals(200, statusCode);
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            }
        });
    }

}